package com.neuedu.funlifebbs.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Notices;
import com.neuedu.funlifebbs.dao.NoticesMapper;
import com.neuedu.funlifebbs.query.NoticesQuery;
import com.neuedu.funlifebbs.service.NoticesService;

/**
 * 
 * @author hw
 * @version 2019年8月19日上午10:56:30
 * 
 */
@Service
public class NoticesServiceImpl implements NoticesService {

	@Autowired
	NoticesMapper noticesMapper;
	
	@Override
	public Notices findById(int id) {
		return noticesMapper.findById(id);
	}
	
	@Override
	public PageInfo<Notices> query(NoticesQuery noticesQuery) {
		if(noticesQuery.isPaging()) {
			PageHelper.startPage(noticesQuery.getPageNum(),noticesQuery.getLimit());
			Page<Notices> pageInfo = (Page<Notices>) noticesMapper.query(noticesQuery);
			return pageInfo.toPageInfo();
		}else {
			PageInfo<Notices> pageInfo = new PageInfo<Notices>(noticesMapper.query(noticesQuery));
			return pageInfo;
		}
	}

	@Override
	public int add(Notices notices) {
		return noticesMapper.add(notices);
	}

	@Override
	public int deleteById(int id) {
		return noticesMapper.deleteById(id);
	}

	@Override
	public int update(Notices notices) {
		return noticesMapper.update(notices);
	}

}
